<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1 {
            width: 100px;
            height: 100px;
            margin-bottom: 20px;
            background-color: pink;
        }

        .box2 {
            width: 100px;
            height: 100px;
            margin-top: 10px;
            background-color: green;
        }
    </style>
</head>

<body>
    <div>
        <!-- 由于 .box1 和 .box2 处于同一个 BFC，所以上下边距进行了合并 -->
        <div class="box1"></div>
        <div class="box2"></div>
    </div>
    <!-- 解决：处于不同的 BFC 就好啦 -->
    <div style="overflow: hidden;">
        <div class="box1"></div>
    </div>
    <div style="overflow: hidden;">
        <div class="box2"></div>
    </div>
</body>

</html>